package cn.xd.core.converter;

import cn.xd.core.ddd.value.basic.Value;
import org.mapstruct.TargetType;

import java.io.Serializable;

/**
 * @author : mirzaLin
 * @data : 2023/11/20
 * @description :  do和实体转化
 **/
public class ReferenceMapper {
    public <T extends Serializable> T resolve(Value<T> value, @TargetType Class<T> entityClass) {
        if (value == null) {
            return null;
        }
        return value.getValue();
    }

    public <T extends Serializable, R extends Value<T>> R toReference(T obj, @TargetType Class<R> entityClass) throws IllegalAccessException, InstantiationException {
        R r = entityClass.newInstance();
        r.setValue(obj);
        return r;
    }

}
